package com.lc.qianrenshiye.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.lc.qianrenshiye.R;
import com.lc.qianrenshiye.conn.CutPriceListPost;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2016/12/1.
 */
public class FullCutAdapter extends ArrayAdapter<CutPriceListPost.FullCutPriceEntity> {

    private LayoutInflater layoutInflater;
    private Context context;
    public int selFullCutPosition = -1;

    public FullCutAdapter(Context context, List<CutPriceListPost.FullCutPriceEntity> cutLists) {
        super(context, 0,cutLists);

        this.context = context;

        layoutInflater = LayoutInflater.from(context);

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        CutPriceListPost.FullCutPriceEntity fullCutPriceEntity = getItem(position);

        ViewHolder viewHolder;

        if (convertView== null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_cut_grid, null)));

            convertView.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) convertView.getTag();
        }

        if (selFullCutPosition == position) {

            viewHolder.item_cut_grid_tv.setTextColor(context.getResources().getColor(R.color.white));
            viewHolder.item_cut_grid_tv.setBackgroundColor(context.getResources().getColor(R.color.red_color));

        } else {

            viewHolder.item_cut_grid_tv.setTextColor(context.getResources().getColor(R.color.black_text_color));
            viewHolder.item_cut_grid_tv.setBackgroundColor(context.getResources().getColor(R.color.not_pay_order_color));

        }

        viewHolder.item_cut_grid_tv.setText(fullCutPriceEntity.money + "元");

        return convertView;
    }

    class ViewHolder {

        @BoundView(R.id.item_cut_grid_tv) private TextView item_cut_grid_tv;

    }

}
